package cn.sh.library.gmwx.config;

import java.sql.SQLException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import virtuoso.jdbc4.VirtuosoConnectionPoolDataSource;

@ComponentScan
@Configuration
public class VirtDataSourceConfig {

	@Autowired
	private VirtuosoConnProperties virtConn;
	
	 @Autowired
	private ApplicationArguments applicationArguments;
	
	@Bean
    public VirtuosoConnectionPoolDataSource getVirtuosoConnectionPoolDataSource() {
//		System.out.println(applicationArguments.getNonOptionArgs());
//		System.out.println(applicationArguments.getOptionNames());
		
//		for(String str: applicationArguments.getSourceArgs()) {
//			System.out.println(str);
//		}
//		System.out.println(applicationArguments.getSourceArgs());
		
		
		VirtuosoConnectionPoolDataSource dataSource = new VirtuosoConnectionPoolDataSource();
		dataSource.setServerName(virtConn.getHost());
		dataSource.setPortNumber(virtConn.getPort()) ;
		dataSource.setUser(virtConn.getUser());
		dataSource.setPassword(virtConn.getPassword());
		dataSource.setCharset(virtConn.getCharset());
//		System.out.println(dataSource.getServerName());
//		System.out.println(dataSource.getPortNumber());
		try {
			dataSource.setInitialPoolSize(virtConn.getPoolSize());
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return dataSource;
    }   
}
